package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcqxYhjsMapper;
import com.hsoft.zhxy.app.common.model.entity.JcqxYhjs;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcqxYhjsService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 用户角色 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcqxYhjsServiceImpl extends BaseService implements JcqxYhjsService {

    @Autowired
    private JcqxYhjsMapper jcqxYhjsMapper;


    /**
     * 查询单条数据
     * @param jcqxYhjs
     * @return
     */
    public JSONObject findOne(JcqxYhjs jcqxYhjs) {
        JcqxYhjs rs = jcqxYhjsMapper.selectOne(new QueryWrapper<JcqxYhjs>().setEntity(jcqxYhjs));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcqxYhjs
     * @return
     */
    public JSONObject findList(JcqxYhjs jcqxYhjs) {
        List<JcqxYhjs> list = jcqxYhjsMapper.selectList(new QueryWrapper<JcqxYhjs>().setEntity(jcqxYhjs));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcqxYhjs
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcqxYhjs jcqxYhjs, long page, long pageSize) {

        Page<JcqxYhjs> pageObj = new Page<JcqxYhjs>(page, pageSize);
        IPage<JcqxYhjs> result = jcqxYhjsMapper.selectPage(pageObj, new QueryWrapper<JcqxYhjs>().setEntity(jcqxYhjs));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcqxYhjs
     * @return
     */
    public JSONObject add(JcqxYhjs jcqxYhjs) {
        jcqxYhjs.setCjsj(LocalDateTime.now());
        jcqxYhjs.setCjr(getYhid());
        jcqxYhjs.setBgsj(LocalDateTime.now());
        jcqxYhjs.setBgr(getYhid());
        return ResultBody.setData(jcqxYhjsMapper.insert(jcqxYhjs));
    }


    /**
     * 修改
     * @param jcqxYhjs
     * @return
     */
    public JSONObject update(JcqxYhjs jcqxYhjs) {
        jcqxYhjs.setBgsj(LocalDateTime.now());
        jcqxYhjs.setBgr(getYhid());
        return ResultBody.setData(jcqxYhjsMapper.updateById(jcqxYhjs));
    }


    /**
     * 删除
     * @param jcqxYhjs
     * @return
     */
    public JSONObject delete(JcqxYhjs jcqxYhjs) {
        return ResultBody.setData(jcqxYhjsMapper.delete(new QueryWrapper<JcqxYhjs>().setEntity(jcqxYhjs)));
    }


}
